import 'module-alias/register';
import Koa from 'koa';
import Router from '@koa/router';
import { koaBody } from 'koa-body';
import logger from 'koa-logger';
import dotenv from 'dotenv';
import { userRouter } from './routes/user.routes';
import { errorHandler } from './middleware/error.middleware';
import { logger as winstonLogger } from './utils/logger';

// Load environment variables
dotenv.config();

const app = new Koa();
const router = new Router();

// Middleware
app.use(logger());
app.use(koaBody());
app.use(errorHandler);

// Routes
router.use('/api/users', userRouter.routes());

// Register all routes
app.use(router.routes()).use(router.allowedMethods());

const PORT = process.env.PORT || 3000;

app.listen(PORT, () => {
  winstonLogger.info(`Server running on port ${PORT}`);
});
